package com.cyclingAssistant.overlays;

import java.util.ArrayList;
import java.util.List;

import org.osmdroid.DefaultResourceProxyImpl;
import org.osmdroid.ResourceProxy;
import org.osmdroid.views.overlay.ItemizedIconOverlay;
import org.osmdroid.views.overlay.OverlayItem;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.TabHost;

import com.cyclingAssistant.project.CyclingAssistantActivity;
import com.cyclingAssistant.project.TabMenu;

public class EndPointItemOverlay extends ItemizedIconOverlay<OverlayItem> {
	static Context mContext;


	public EndPointItemOverlay (Drawable pDefaultMarker, Context ct) {
		super(new ArrayList<OverlayItem>(), pDefaultMarker, new ItemTapListener(), new DefaultResourceProxyImpl(ct));
		mContext = ct;
	}

	

	public EndPointItemOverlay(
			List<OverlayItem> pList,
			Drawable pDefaultMarker,
			org.osmdroid.views.overlay.ItemizedIconOverlay.OnItemGestureListener<OverlayItem> pOnItemGestureListener,
			ResourceProxy pResourceProxy) {
		super(pList, pDefaultMarker, pOnItemGestureListener, pResourceProxy);
		// TODO Auto-generated constructor stub
	}


	public static class ItemTapListener implements
			OnItemGestureListener<OverlayItem> {

		@Override
		public boolean onItemLongPress(int index, OverlayItem item) {
			// TODO Auto-generated method stub
			return false;
		}

		@Override
		public boolean onItemSingleTapUp(int index, final OverlayItem item) {
			// TODO Auto-generated method stub

				AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
				dialog.setTitle(item.getTitle());
				dialog.setMessage(item.getSnippet());
				dialog.setPositiveButton("remove", new OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {

						CyclingAssistantActivity.mapView.getOverlays().clear();
						CyclingAssistantActivity.navi_info.setVisibility(View.GONE);
						CyclingAssistantActivity.search_bar.setVisibility(View.VISIBLE);
					}
				});
				dialog.setNeutralButton("save", new OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						TabHost tabHost = (TabHost) TabMenu.tabHost;
						tabHost.setCurrentTab(3);

					}
				});
				dialog.setNegativeButton("back", new OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
					}
				});
				dialog.show();

			return true;
		}
	}
}
